package io.renren.modules.generator.controller;

import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.generator.entity.LeaveMessageEntity;
import io.renren.modules.generator.service.LeaveMessageService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 *
 *
 * @author guijing
 * @email sunlightcs@gmail.com
 * @date 2022-05-16 23:22:15
 */
@RestController
@RequestMapping("generator/leavemessage")
public class LeaveMessageController {
    @Autowired
    private LeaveMessageService leaveMessageService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        Page<Map<String, Object>> page = new Page<>(Long.valueOf(String.valueOf(params.get("page"))), Long.valueOf(String.valueOf(params.get("limit"))));
        IPage<Map<String, Object>> mapIPage = leaveMessageService.selectComment(page, params);
        PageUtils newPage = new PageUtils(mapIPage);
        return R.ok().put("page", newPage);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{leaveId}")
    public R info(@PathVariable("leaveId") Integer leaveId){
		LeaveMessageEntity leaveMessage = leaveMessageService.getById(leaveId);

        return R.ok().put("leaveMessage", leaveMessage);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody LeaveMessageEntity leaveMessage){
		leaveMessageService.save(leaveMessage);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody LeaveMessageEntity leaveMessage){
		leaveMessageService.updateById(leaveMessage);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] leaveIds){
		leaveMessageService.removeByIds(Arrays.asList(leaveIds));

        return R.ok();
    }

}
